using System;
using System.Web.Security;

using Wayloop.Fusion.Core.Objects;
using Wayloop.Fusion.Web.UI;

namespace Wayloop.Fusion.WebClient
{
    public partial class LoginPage : FusionPage
    {
        public LoginPage()
        {
            Init += LoginPage_Init;
        }


        private void LoginPage_Init(object sender, EventArgs e)
        {
            LoginButton.Click += LoginButton_Click;
        }


        private void LoginButton_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                User user = DataContext.User.GetByUsername(Username.Text);

                if (user != null && user.Password.Equals(Password.Text))
                {
                    FormsAuthentication.RedirectFromLoginPage(user.Username, RememberMe.Checked);
                }
                else
                {
                    Response.Write("LOGIN FAILED!!!");
                }
            }
        }
    }
}